package com.jyw.business.ast.domain.dto.web;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.ast.constant.AstRelationConstant;
import com.jyw.business.ast.domain.AstBorrow;
import com.jyw.business.ast.domain.AstDealRelation;
import com.jyw.business.ast.domain.AstInfo;
import com.jyw.business.ast.service.IAstInfoService;
import com.jyw.common.annotation.Excel;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.common.utils.spring.SpringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 资产-借用信息对象 ast_borrow
 * 
 * @author system
 * @date 2023-10-19
 */
@Data
@ApiModel("资产借用-借用申请")
public class AstBorrowDto
{

    /** 借出科室 */
    @ApiModelProperty("借出科室")
    private Long outDept;

    /** 联系人 */
    @ApiModelProperty("联系人")
    private String inUser;

    /** 联系电话 */
    @ApiModelProperty("联系电话")
    private String inPhone;

    /** 预计归还日期 */
    @ApiModelProperty("预计归还日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date estimateReturnDate;

    /** 借用原因 */
    @ApiModelProperty("借用原因")
    private String reason;

    @ApiModelProperty("借用资产集合")
    private List<Long> astList;

    public AstBorrow buildBorrow() {
        AstBorrow borrow = new AstBorrow();
        BeanUtils.copyProperties(this,borrow);
        borrow.setAuditState("0");
        borrow.setState("1");
        borrow.setCreateUser(SecurityUtils.getUserId());
        borrow.setInDept(SecurityUtils.getDeptId());
        borrow.setCreateTime(DateUtils.getNowDate());
        return borrow;
    }

    public List<AstDealRelation> buildRelation(AstBorrow borrow) {
        return getAstList().stream().map(data -> {
            AstDealRelation relation = new AstDealRelation();
            relation.setType(AstRelationConstant.BORROW);
            relation.setBusinessId(borrow.getId());
            relation.setOutDept(getOutDept());
            relation.setInDept(borrow.getInDept());
            relation.setAstId(data);
            return relation;
        }).collect(Collectors.toList());
    }
}
